<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>环形进度条</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    .outermost {
      position: relative;
    }

    .left-box,
    .right-box {
      width: 100px;
      height: 200px;
      background: pink;
      overflow: hidden;
      /* display: inline-block; */
    }

    .right-box {
      position: absolute;
      left: 100px;
      top: 0;
    }

    .left-circle,
    .right-circle {
      width: 200px;
      height: 200px;
      border: 20px solid transparent;
      border-top: orange solid 20px;
      border-left: orange solid 20px;
      border-radius: 50%;
      transform: rotate(-225deg);
    }

    .right-circle {
      transform: translateX(-50%) rotate(315deg);
    }
  </style>

</head>

<body>
  <h1>环形进度条</h1>
  <div class="outermost">
    <div class='container'>
      <div class="left-box">
        <div class='left-circle'></div>
      </div>
      <div class="right-box">
        <div class='right-circle'></div>
      </div>
    </div>
    <input type="number" id="inp">
  </div>
  <script>

    const inp = document.querySelector('#inp')

    inp.onkeyup = (e) => {
      console.log(e);
      if (e.keyCode === 13) {
        const leftCircle = document.querySelector('.left-circle')
        const rightCircle = document.querySelector('.right-circle')

        leftCircle.style.animation = ''
        rightCircle.style.animation = ''

        const degree = Number(inp.value)
        let deg = degree > 360 ? degree % 360 : degree

        const leftDeg = () => deg > 180 ? -45 : -deg + 135
        const rightDeg = () => deg > 180 ? 315 - deg - 180 + 360 : 315


        leftCircle.style.animation = `left ${deg / 100}s linear forwards`

        rightCircle.style.animation = `right ${(deg - 180) / 100}s ${deg / 100}s linear forwards`

        if (document.querySelector('.ring')) {
          let ring = document.querySelector('.ring')
          console.log(80, ring);

          ring.innerHTML = ''
        }

        const keyframes = ` 
        @keyframes left {
          0% {
              transform:  rotate(135deg);
            }
            100% {
              transform:  rotate(${leftDeg()}deg);
            }
          } 
        @keyframes right {
        0% {
            transform: translateX(-50%) rotate(315deg);
          }
          100% {
            transform: translateX(-50%) rotate(${rightDeg()}deg);
          }
        }`

        const style = document.createElement('style')

        style.type = 'text/css'

        style.className = 'ring'

        style.innerHTML = keyframes

        let head = document.querySelector('head').appendChild(style)
      }
    }


  </script>
</body>